package com.asset.dispoal.file.feature.service.command;

import com.asset.dispoal.file.feature.domain.db.entity.FileFeatureTableExpand;
import com.asset.dispoal.file.feature.domain.db.mapper.FileFeatureTableMapper;
import com.asset.dispoal.file.feature.dto.FileFeatureTableExpandCreateRequest;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.date.DateTimeUtil;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.core.id.BaseIdeable;
import tech.mhuang.pacebox.springboot.core.local.GlobalHeaderThreadLocal;
import tech.mhuang.pacebox.springboot.protocol.Result;

@Component
public class CreateFileFeatureTableExpandCommand implements BaseCommand<FileFeatureTableExpandCreateRequest, Result> {

    @Autowired
    FileFeatureTableMapper fileFeatureTableMapper;

    @Autowired
    BaseIdeable<String> ideable;

    @SneakyThrows
    @Override
    public Result execute(FileFeatureTableExpandCreateRequest request) {
        String id = ideable.generateId();
        String userId = GlobalHeaderThreadLocal.getOrException().getUserId();
        FileFeatureTableExpand fileFeatureTable = new FileFeatureTableExpand();
        fileFeatureTable.setId(id);
        fileFeatureTable.setFeatureTableId(request.getFeatureTableId());
        fileFeatureTable.setType(request.getType());
        fileFeatureTable.setAlias(request.getAlias());
        fileFeatureTable.setField(request.getField());
        fileFeatureTable.setSheetPage(request.getSheetPage());
        fileFeatureTable.setLocation(request.getLocation());
        fileFeatureTable.setEvidenceTypeId(request.getEvidenceTypeId());
        fileFeatureTable.setFromKeyword(request.getFromKeyword());
        fileFeatureTable.setEndKeyword(request.getEndKeyword());
        fileFeatureTable.setCreateUserId(userId);
        fileFeatureTable.setCreateTime(DateTimeUtil.currentDate());
        fileFeatureTableMapper.insertExpand(fileFeatureTable);
        return Result.ok();
    }

}
